-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when using catch
after try
#59847
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @michaelwoerister (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@@ -3618,7 +3618,14 @@ impl<'a> Parser<'a> { | |||
{ | |||
let (iattrs, body) = self.parse_inner_attrs_and_block()?; | |||
attrs.extend(iattrs); | |||
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs)) | |||
if self.eat_keyword(keywords::Catch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be preferable to ban any form of try { ... } $ident { .. }
from a perspective of having maximum flexibility in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should those all suggest match
instead, or should that just be catch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @estebank ^-- I would probably say yes, but that's more a diagnostics issue than future lang design flexibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of the following case:
let _ = try {
true
}
let _ = ();
where the error is the lack of ;
, which is why I'm a bit weary of suggesting the right syntax for every ident. The current output for this the following, which I feel doesn't hinder understanding more than complaining about an inexistent catch
would:
error: expected one of `.`, `;`, `?`, or an operator, found `let`
--> src/main.rs:7:5
|
6 | }
| - expected one of `.`, `;`, `?`, or an operator here
7 | let _ = ();
| ^^^ unexpected token
@@ -3618,7 +3618,14 @@ impl<'a> Parser<'a> { | |||
{ | |||
let (iattrs, body) = self.parse_inner_attrs_and_block()?; | |||
attrs.extend(iattrs); | |||
Ok(self.mk_expr(span_lo.to(body.span), ExprKind::TryBlock(body), attrs)) | |||
if self.eat_keyword(keywords::Catch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of the following case:
let _ = try {
true
}
let _ = ();
where the error is the lack of ;
, which is why I'm a bit weary of suggesting the right syntax for every ident. The current output for this the following, which I feel doesn't hinder understanding more than complaining about an inexistent catch
would:
error: expected one of `.`, `;`, `?`, or an operator, found `let`
--> src/main.rs:7:5
|
6 | }
| - expected one of `.`, `;`, `?`, or an operator here
7 | let _ = ();
| ^^^ unexpected token
r? @estebank |
The only action item from me would be rewording the error message and maybe fleshing out the |
Out of the house right now so I'll work on all that when I can, thanks for the reviews! |
Tests passed @estebank |
Didn't realize I accidentally closed this, 🤦♂️ |
@bors r+ |
📌 Commit 1156ce6 has been approved by |
@estebank This still accepts |
@Centril I can do that in a separate PR later. |
@Kampfkarren Excellent! Thank you. |
It doesn't accept it, it just keeps the current
right? |
@estebank Yes, but I'm assuming he meant an explicit check against it for forwards compatibility? |
Not sure... I'll have a look on nightly once this is merged... :) |
…bank Error when using `catch` after `try` Part of rust-lang#31436
Rollup of 8 pull requests Successful merges: - #59781 (Remove check_match from const_eval) - #59820 (proc_macro: stop using LEB128 for RPC.) - #59846 (clarify what the item is in "not a module" error) - #59847 (Error when using `catch` after `try`) - #59859 (Suggest removing `?` to resolve type errors.) - #59862 (Tweak unstable diagnostic output) - #59866 (Recover from missing semicolon based on the found token) - #59892 (Impl RawFd conversion traits for WASI TcpListener, TcpStream and UdpSocket) Failed merges: r? @ghost
Part of #31436